#!/usr/bin/env python3

import sys
import subprocess
import robust_layer.git

if len(sys.argv) < 2:
    print("Not enough parameters", file=sys.stderr)
    sys.exit(1)

try:
    if sys.argv[1] == "clone":
        robust_layer.git.clone(*sys.argv[2:])
    elif sys.argv[1] == "fetch":
        robust_layer.git.fetch(*sys.argv[2:])
    elif sys.argv[1] == "pull":
        robust_layer.git.pull(*sys.argv[2:])
    elif sys.argv[1] == "push":
        robust_layer.git.push(*sys.argv[2:])
    else:
        print("Operation \"%s\" not supported" % (sys.argv[1]), file=sys.stderr)
        sys.exit(1)
except robust_layer.git.PrivateUrlNotExistError:
    print("Unrecoverable error: Private URL doest not exist.", file=sys.stderr)
    sys.exit(1)
except subprocess.CalledProcessError as e:
    sys.exit(e.returncode)